<?php

class Application_Model_DbTable_Address extends Zend_Db_Table_Abstract
{
    // ZendAjax
    protected $_name = 'address';

    public function getCity($keyword = '')
    {
        if(empty($keyword)) return;
        if(mb_strlen($keyword) < 3) return;

        $keyword = $keyword . '%';

        $select = $this->select()
                        ->distinct()
                        ->from(array('a' => 'address'), array('city'))
                        ->where('city LIKE ?', $keyword)
                        ->order(array('city'));

        return $this->fetchAll($select);
    }

    public function getZipCode($keyword = '')
    {
        if(empty($keyword)) return;
        if(mb_strlen($keyword) < 4) return;

        $keyword = $keyword . '%';

        $select = $this->select()
                        ->distinct()
                        ->from(array('a' => 'address'), array('zipCode'))
                        ->where('zipCode LIKE ?', $keyword)
                        ->order(array('zipCode'));

        return $this->fetchAll($select);
    }
}

